import { useRef } from "react";
import { Button } from "antd";
import { PlusOutlined, ExclamationCircleOutlined } from "@ant-design/icons";
import { QueryPage } from "@components";
import { fields, GetColumns, ModalFields } from "./config";
import { findTemplates, editTemplateById } from "@apis/informTemplateApi";
import { useMainContext } from '@contexts/MainContext'

const InformTemplate = () => {
  const { isButtomShow } = useMainContext()

  const queryFormRef = useRef("queryFormRef");
  const formProps = {
    formRef: queryFormRef,
    fields: fields,
    initialValues: {
      status: '1',
    },
    extraTail: (
      <>
        {isButtomShow('430102') && <Button icon={<PlusOutlined />} onClick={() => modalRef.current.showModal()}>
          新增
        </Button>}
      </>
    ),
  };

  //编辑
  const edit = (record) => {
    modalRef.current.showModal(record);
  };

  const tableProps = {
    rowKey: "msgTempId",
    columns: GetColumns( queryFormRef, edit ),
  };

  const modalRef = useRef("modalRef");
  const modalFormProps = {
    fields: ModalFields(),
    initialValues: {
      status: '1',
    },
  };

  return (
    <QueryPage
      formProps={formProps}
      tableProps={tableProps}
      queryApi={findTemplates}
      modalRef={modalRef}
      modalFormProps={modalFormProps}
      addApi={editTemplateById}
      updataId="msgTempId"
      updataApi={editTemplateById}
    />
  );
};

export default InformTemplate;
